import { Context, Next } from "koa";
import { File, Files } from "formidable";
import fs from "fs";
import path from "path";
import { resultSuccessJson } from "../util/resultError";
import { SERVICE } from "../config/api.config";

/***
 * 上传单个 图片
 **/
export const UploadContentImg = (ctx: Context, next: Next) => {
  const file = (ctx.request.files as Files).file as File;
  console.log(file)
  ctx.body = resultSuccessJson(undefined, "内容添加成功", {
    filePath: SERVICE.HOST + file.path.split("static")[1],
  });
  return next;
};

/***
 * 上传内容markdown 文件
 **/
export const UploadContentMD = async (ctx: Context, next: Next) => {
  const file = (ctx.request.files as Files).file as File;
  ctx.body = resultSuccessJson(undefined, "内容添加成功", {
    filePath: SERVICE.HOST + file.path.split("static")[1],
  });
  return next;
};
